<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="submitForm"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <j-form-container :disabled="formDisabled">
        <a-form :form="form">
          <a-row>
            <a-col :xs="24" :sm="12">
              <a-form-item label="线路" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['routeNames']" placeholder=" "></a-input>
              </a-form-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['storeName']" placeholder=" "></a-input>
              </a-form-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['payTimeStart']" placeholder=" "></a-input>
                <!--                <a-date-picker-->
                <!--                  v-decorator="['payTimeStart']"-->
                <!--                  :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"-->
                <!--                />-->
              </a-form-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <!--                <a-date-picker-->
                <!--                  :wrapperCol="wrapperCol"-->
                <!--                  v-decorator="['payTimeEnd']"-->
                <!--                  :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"-->
                <!--                />-->
                <a-input v-decorator="['payTimeEnd']" placeholder=" "></a-input>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
import pick from 'lodash.pick'
import { pustGenerateShipmentGoodsBill } from '@/api/order'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
import Area from '@/components/_util/Area'
import moment from 'moment'
export default {
  name: 'OrderDeliveryModel',
  mixins: [JEditableTableMixin],

  props: {
    //流程表单data
    formData: {
      type: Object,
      default: () => {},
      required: false,
    },
    //表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false,
    },
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 },
      },
      refKeys: ['orderGoods'],
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    },
  },
  created() {
    //如果是流程中表单，则需要加载流程表单data
    // this.showFlowData();
    this.pcaData = new Area()
  },
  methods: {
    // getAllTable() {
    //   let values = this.tableKeys.map(key => getRefPromise(this, key))
    //   return Promise.all(values)
    // },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      let fieldval = pick(this.model, 'routeNames', 'storeName', 'payTimeStart', 'payTimeEnd')
      this.$nextTick(() => {
        // this.city = this.model.receiverRegion
        this.form.setFieldsValue(fieldval)
      })
    },
    moment,
    popupCallback(row) {
      let type
      if (row.shopownerId !== undefined) {
        type = 'routeId'
      } else {
        type = 'storeId'
      }
      this.form.setFieldsValue(pick(row, 'routeNames', 'storeName'))
      this.queryParam[type] = row[type]
    },
    submitForm() {
      pustGenerateShipmentGoodsBill(
        pick(this.model, 'orderId', 'storeId', 'payTimeStart', 'payTimeEnd', 'routeIds')
      ).then((res) => {
        let { success, message } = res
        this.visible = false
        if (success) {
          this.$message.success('生成出货单成功，请前往出货单模块查看')
        } else {
          this.$message.warning(message)
        }
      })
    },
    // /** 整理成formData */
    // classifyIntoFormData(allValues) {
    //   let main = Object.assign(this.model, allValues.formValue)
    //
    //   return {
    //     ...main, // 展开
    //     orderGoodsList: allValues.tablesValue[0].values,
    //   }
    // },
  },
}
</script>

<style scoped>
</style>